package com.zhs.blog.controller;

import com.zhs.blog.domain.ResponseResult;
import com.zhs.blog.domain.entity.Article;
import com.zhs.blog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: ArticleController
 * @Descripiton: 文章控制类
 * @Author: 小郑
 * @Date： 2025/5/9 21:17
 * @Version：1.8
 **/
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;


    /**
     * 查询热门文章
     *
     * @return
     */
    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList() {
        // 查询热门文章接口，封装成ResponseResult返回
        ResponseResult result = articleService.hotArticleList();
        return result;
    }

    /**
     * 分页查询文章列表
     * @param pageNum
     * @param pageSize
     * @param categoryId
     * @return
     */
    @GetMapping("/articleList")
    public ResponseResult articleList(Integer pageNum,Integer pageSize,Long categoryId){
        return articleService.articleList(pageNum,pageSize,categoryId);
    }

    /**
     * 查询文章详情
     * 请求url /article/{id}
     * @param id
     * @return
     */

    @GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable("id") Long id){
        return articleService.getArticleDetail(id);
    }


    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }

}